class Solution {
private:

    unordered_map<char, int> mp = {{'a', 0}, {'e', 0}, {'i', 0}, {'o', 0}, {'u', 0}};

    bool judge_all_appear(){
        return mp['a'] && mp['i'] && mp['o'] && mp['u'] && mp['e'];
    }

    bool judge_for_letter(char x){
        switch (x)
        {
        case 'a':return !mp['e'] && !mp['i'] && !mp['o'] && !mp['u'];
            break;
        case 'e':return mp['a'] && !mp['i'] && !mp['o'] && !mp['u'];
            break;
        case 'i':return mp['a'] && mp['e'] && !mp['o'] && !mp['u'];
            break;
        case 'o':return mp['a'] && mp['e'] && mp['i'] && !mp['u'];
            break;
        case 'u':return mp['a'] && mp['e'] && mp['i'] && mp['o'];
            break;
        }
        return false;
    }

public:
    int longestBeautifulSubstring(string word) {
        int i = 0, j = 0;
        int ans = 0;
        while(j < word.length()){
            while(!judge_for_letter(word[j]) && i < j){ 
                mp[word[i]]--;
                i++;
            }
            mp[word[j]]++;
            if(judge_all_appear())ans = max(ans, j - i + 1);
            j++;
        }
        return ans;
    }
};

//2021.4.25
